package org.jeecg.modules.flow.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.flow.entity.ActHiTaskInstance;
import org.jeecg.modules.flow.query.HistoryTaskQuery;
import org.jeecg.modules.flow.service.IActHiTaskInstanceService;
import org.jeecg.modules.flow.vo.HistoryTaskInstanceVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @Description: act_hi_taskinst
 * @Author: jeecg-boot
 * @Date: 2021-12-30
 * @Version: V1.0
 */
@Api(tags = "历史流程任务API")
@RestController
@RequestMapping("/flow/actHiTaskinst")
@Slf4j
public class ActHiTaskInstanceController extends JeecgController<ActHiTaskInstance, IActHiTaskInstanceService> {
    @Autowired
    private IActHiTaskInstanceService actHiTaskinstService;

    /**
     * 分页列表查询
     *
     * @param actHiTaskInstance
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    @ApiOperation(value = "act_hi_taskinst-分页列表查询", notes = "act_hi_taskinst-分页列表查询")
    @GetMapping(value = "/list")
    public Result<?> queryPageList(ActHiTaskInstance actHiTaskInstance,
                                   @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                   @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                   HttpServletRequest req) {
        QueryWrapper<ActHiTaskInstance> queryWrapper = QueryGenerator.initQueryWrapper(actHiTaskInstance, req.getParameterMap());
        Page<ActHiTaskInstance> page = new Page<ActHiTaskInstance>(pageNo, pageSize);
        IPage<ActHiTaskInstance> pageList = actHiTaskinstService.page(page, queryWrapper);
        return Result.OK(pageList);
    }

    @ApiOperation(value = "分页查询历史任务", notes = "act_hi_taskinst-分页查询历史任务")
    @GetMapping(value = "/queryHistoricTaskInstances")
    public Result<Page<HistoryTaskInstanceVo>> queryHistoricTaskInstances(HistoryTaskQuery query,
                                                                          @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                                          @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        Page<HistoryTaskInstanceVo> page = actHiTaskinstService.queryHistoricTaskInstances(query, pageNo, pageSize);
        return Result.OK(page);
    }


}
